{
  "properties" : { },
  "id" : "8d4d9afc903e44119f9489180dcc6954",
  "script" : null,
  "groupId" : "ded0996d4aa14841ae2d40edb1fa6d63",
  "name" : "新增设备",
  "createTime" : 1727071128292,
  "updateTime" : 1726305183415,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "saveDevice",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"snCode\": \"\",\r\n    \"deviceName\": \"\",\r\n    \"ip\": \"192.100.5.21\",\r\n    \"dccId\": \"1803254752905129985\",\r\n    \"operateDate\": \"\",\r\n    \"deviceUsername\": \"root\",\r\n    \"devicePassword\": \"Admin@9000\",\r\n    \"protype\": \"1\",\r\n    \"devicePort\": \"22\",\r\n    \"snmpVersion\": \"1\",\r\n    \"communityR\": \"public\",\r\n    \"communityRW\": \"private\",\r\n    \"portRW\": \"161\",\r\n    \"deviceModelId\": \"\",\r\n    \"stationProp\": 4,\r\n    \"stationType\": 5,\r\n    \"deviceType\": 2,\r\n    \"openStatus\": \"\",\r\n    \"deviceFirm\": 2,\r\n    \"voltageLevel\": 2,\r\n    \"accessNetwork\": 1,\r\n    \"netRegion\": 3,\r\n    \"name\": \"\"\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": {\n        \"code\": 400,\n        \"success\": false,\n        \"data\": {},\n        \"msg\": \"保存的设备信息中，IP地址有重复，请修改后重新保存\"\n    }\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "snCode",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceName",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "ip",
      "value" : "192.100.5.21",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "dccId",
      "value" : "1803254752905129985",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "operateDate",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceUsername",
      "value" : "root",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "devicePassword",
      "value" : "Admin@9000",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "protype",
      "value" : "1",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "devicePort",
      "value" : "22",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "snmpVersion",
      "value" : "1",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "communityR",
      "value" : "public",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "communityRW",
      "value" : "private",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "portRW",
      "value" : "161",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceModelId",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "stationProp",
      "value" : "4",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "stationType",
      "value" : "5",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceType",
      "value" : "2",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "openStatus",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceFirm",
      "value" : "2",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "voltageLevel",
      "value" : "2",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "accessNetwork",
      "value" : "1",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "netRegion",
      "value" : "3",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "name",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  },
  "responseBodyDefinition" : {
    "name" : null,
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }
}
================================
import org.springblade.core.tool.api.R
import com.kd.ndmp.util.IdUtil
import org.springframework.util.CollectionUtils
import org.springblade.core.tool.utils.StringUtil

var detailTemp = db.table("ndmp_device").where().eq("ip", body.ip).selectOne();
if (detailTemp != null) {
    return R.fail("保存的设备信息中，IP地址有重复，请修改后重新保存");
}

String deviceId = IdUtil.generateDeviceId(body.ip);

//  同一个设备  不同ip  口的  ，要禁止增加
var list = db.table("ndmp_net_device_ip_chart").where().eq("ip_ad_ent_addr", body.ip).select();

if (!CollectionUtils.isEmpty(list)) {

    var netDeviceIpChart = list.get(0);
    NdmpDevice hasDevice = db.table("ndmp_device").where().eq("id", netDeviceIpChart.get("deviceId")).selectOne();
    return R.fail("与保存的设备信息重复, 设备名称：" + hasDevice.get("deviceName") +
        "设备ip:" + hasDevice.get("ip") +
        "设备机构id:" + hasDevice.get("groupId") +
        "该设备的 ifindex :" + netDeviceIpChart.get("ipAdEntIfIndex") +
        "位置的ip 重复");
}


var stationType
if (!StringUtil.isEmpty(body.stationType)) {
    stationType = body.stationType //厂站类型
} else {
    stationType = 6; //厂站类型
}


var val = db.transaction(() => {

    // 保存到监控对象表
    var v1 = db.table('ndmp_device').primary('id').insert({
        id: deviceId, //id
        snCode: body.snCode, // sn code
        deviceAlias: body.deviceAlias, //场站名称= 设备别名
        groupId: body.groupId, //站点属性  地网 省网
        stationProp: body.stationProp, //所属场站
        ip: body.ip, // ip地址
        deviceModelId: body.deviceModelId, //设备型号
        voltageLevel: body.voltageLevel, //电压类型
        operateDate: body.operateDate, // 投运时间
        deviceName: body.deviceName, //设备名称
        dccId: body.dccId, // 将组织机构ID存到dcc_id
        accessNetwork: body.accessNetwork, // 将组织机构ID存到dcc_id
        deviceType: body.deviceType,
        openStatus: body.openStatus,
        netRegion: body.netRegion,
        stationType: stationType
    })


    // 保存到监控对象表
    var v2 = db.table('alarm_target').primary('id').insert({
        code: deviceId,
        target_name: body.deviceName,
        target_type: body.deviceType,
        enable: 1
    })

    //snmp协议静态模型
    var v3 = db.table('ndmp_net_snmp_protocol').primary('id').insert({
        id: IdUtil.getSnowflakeNextId(),
        deviceId: deviceId,
        snmp_version: body.snmpVersion,
        rocommunity: body.communityR,
        rwcommunity: body.communityRW,
        port_rw: body.portRW,
        port_trap: body.portTrap
    })


    //设备协议静态模型
    var v4 = db.table('ndmp_net_device_protocol').primary('id').insert({
        id: IdUtil.getSnowflakeNextId(),
        device_id: deviceId,
        pro_type: body.protype,
        device_username: body.deviceUserName,
        device_password: body.devicePassword,
        device_port: body.devicePort
    })
    return v4;
});
return val;


